import QtQuick 2.0
import QtQuick.Controls 2.3
import QtQuick.Layouts 1.0

Item {
    id:root
    width: 850
    height: 580
    property real minSize:  Math.min(width/850, height/580)



    Item{
        id: sv_this
        width:parent.width
        height: parent.height*0.85
        clip: true
        Text {
            y: 20*root.minSize
            color: "#44f6f6"
            text: qsTr("额定励磁电流参数")
            anchors.horizontalCenter: parent.horizontalCenter
            verticalAlignment: Text.AlignVCenter
            horizontalAlignment: Text.AlignHCenter
            font.pixelSize: 40*root.minSize
        }

        Rectangle {
            y: 90*root.minSize
            anchors.horizontalCenter: parent.horizontalCenter
            width: 400*root.minSize
            height: 380*root.minSize
            color: "#6692e8bc"
            radius: 10*root.minSize

            ColumnLayout {
                property real textSize: 30*root.minSize
                x: 10*root.minSize
                width: 380*root.minSize
                anchors.bottom: parent.bottom
                anchors.top: parent.top

                EXC_Normal_DoubleTextSytle3{
                    id: text_powerNum
                    width: parent.width
                    Layout.preferredHeight: 40*root.minSize
                    Layout.fillWidth: true
                    funcText: qsTr("常规功率柜个数:")
                    valueText: "???"
                    textSize:parent.textSize
                }
                EXC_Normal_DoubleTextSytle3{
                    id: text_power1
                    width: parent.width
                    Layout.preferredHeight: 40*root.minSize
                    Layout.fillWidth: true
                    funcText: qsTr("1#功率柜额定励磁电流:")
                    valueText: "???"
                    textSize:parent.textSize
                }
                EXC_Normal_DoubleTextSytle3{
                    id: text_power2
                    width: parent.width
                    Layout.preferredHeight: 40*root.minSize
                    Layout.fillWidth: true
                    funcText: qsTr("2#功率柜额定励磁电流:")
                    valueText: "???"
                    textSize:parent.textSize
                }
                EXC_Normal_DoubleTextSytle3{
                    id: text_power3
                    width: parent.width
                    Layout.preferredHeight: 40*root.minSize
                    Layout.fillWidth: true
                    funcText: qsTr("3#功率柜额定励磁电流:")
                    valueText: "???"
                    textSize:parent.textSize
                }
                EXC_Normal_DoubleTextSytle3{
                    id: text_power4
                    width: parent.width
                    Layout.preferredHeight: 40*root.minSize
                    Layout.fillWidth: true
                    funcText: qsTr("4#功率柜额定励磁电流:")
                    valueText: "???"
                    textSize:parent.textSize
                }
            }
        }


        Text {
            id: element
            y: 470*root.minSize
            color: "#c3bf1e"
            text: qsTr("*本页参数只下载不回显")
            anchors.horizontalCenter: parent.horizontalCenter
            font.pixelSize: 22*root.minSize
        }

        EXC_Normal_BtnUncheckSecret_debuggerStyle {
            id: btn_ASave
            nameFontpixelSize: 25*root.minSize
            y: 410*root.minSize
            width: 140*root.minSize
            height: 50*root.minSize
            anchors.right: parent.right
            anchors.rightMargin: 40
            nameText: qsTr("保存参数")
            onClicked: {
                timerA.start()
            }

            Timer{
                id:timerA
                interval: 10
                repeat: true
                triggeredOnStart: true
                property int mcounter: 0

                onTriggered: {
                    function writeModSingal(handle, sqlName)
                    {
                        if(handle === "???") return
                        var t_var = Number(handle)
                        $modbusInterface.sl_modbusWriteData($sqlMcDefine.qml_queryTableWriteDef(sqlName), t_var)
                    }
                    var t_var
                    switch(mcounter)
                    {
                    case 0:
                        var modSendVar = new Array
                        var t_flag = true
                        function writeModArray(handle, sqlName)
                        {
                            if(handle === "???") {t_flag = false; return 0}
                            return Number(handle)
                        }
                        modSendVar.push(writeModArray(text_power1.valueText, "1#功率柜额定励磁电流"))
                        modSendVar.push(writeModArray(text_power2.valueText, "2#功率柜额定励磁电流"))
                        modSendVar.push(writeModArray(text_power3.valueText, "3#功率柜额定励磁电流"))
                        modSendVar.push(writeModArray(text_power4.valueText, "4#功率柜额定励磁电流"))
                        if(t_flag)
                        {
                            $modbusInterface.sl_modbusWriteDataArray(
                                        $sqlMcDefine.qml_queryTableWriteDef("1#功率柜额定励磁电流"), modSendVar, 4)
                            writeModSingal(text_powerNum.valueText, "常规功率柜个数保存")
                            timerA.stop();
                            mcounter=0
                        }
                        else
                        {
                            writeModSingal(text_power1.valueText, "1#功率柜额定励磁电流")
                            writeModSingal(text_power2.valueText, "2#功率柜额定励磁电流")
                            mcounter++
                        }
                        break;
                    case 1:
                        writeModSingal(text_power3.valueText, "3#功率柜额定励磁电流")
                        writeModSingal(text_power4.valueText, "4#功率柜额定励磁电流")
                        mcounter++
                        break;
                    default:
                        writeModSingal(text_powerNum.valueText, "常规功率柜个数保存")
                        timerA.stop()
                        mcounter=0
                        break;
                    }
                }
            }
        }

        onFocusChanged:{
            if(!focus) return
            refurbishA()
        }
    }


    EXC_Normal_BtnUncheckStyle {
        id: button3
        nameText: qsTr("返回")
        nameFontpixelSize: 30*Math.min(root.width/850, root.height/580)
        width: parent.width*0.15
        height: parent.height*0.09
        anchors.left: parent.left
        anchors.leftMargin: parent.width*0.75
        anchors.topMargin: parent.height/32
        anchors.top: sv_this.bottom
        onClicked: {
            sw.currentIndex=0
        }
    }
}
